var readGPSLogStep=
{
	title:'Import GPS log',
	createUI:function()
	{
		var ret=$('<div>'+
			'Read Log Params<input type="text" id="readGPSLogStepParam" value="COM4"/><br>'+
			'Tk1 Path<input type="text" id="txtTk1Path" />'+
			'<button id="btnReadGPSLog">Read</button><br>'+
			'GPX Path<input type="text" id="txtGpxPath" />'+
			'<button id="btnConvertTk1ToGpx">Convert</button><br>'+
			'</div>');
		return ret;
	},
	postCreateUI:function()
	{
		$('#txtAlbumPath').change(function(){
			$('#txtTk1Path').attr('value',$('#txtAlbumPath').val()+'\\track\\01.tk1');
			$('#txtTk1Path').change();
		});
		
		$('#txtTk1Path').change(function(){
			$('#txtGpxPath').attr('value',$('#txtTk1Path').val().replace('.tk1','.gpx'));
		});
		$('#btnConvertTk1ToGpx').click(function(){
			var cmd='"'+Environment.scriptPath+'\\convertTk1ToGpx.bat" "'+$('#txtTk1Path').val()+'" "'+$('#txtGpxPath').val()+'"';
			//alert(cmd);
			var oExec=Shell.obj.Exec(cmd);
			
		});
		
		$('#btnReadGPSLog').click(function(){
			var tk1Path=$('#txtTk1Path').val();
			if(!File.makeSurePathExisted(File.objFSO.GetParentFolderName(tk1Path),true)){
				alert('can\'t access the folder:'+File.objFSO.GetParentFolderName(tk1Path));
				return;
			}
			
			var cmd='"'+Environment.binPath+'\\wintecTool\\readlog.exe" -o "'+tk1Path+'" '+$('#readGPSLogStepParam').val();
			var oExec=Shell.obj.Exec(cmd);
			var out=oExec.StdOut.ReadAll();
			var err=oExec.StdErr.ReadAll();
			
			if(/already exists!/.exec(out)!=null){
				alert(
						'The file is already existed:'+tk1Path
				);
				return;
			}
			
			if(/SerialPortException/.exec(err)!=null){
				alert("Can't open serial port. Check you have turned on the GPS Logger.");
				return;
			}
			
			if(/Create /.exec(out)!=null){
				//success
				alert('successful read the log');
				return;
			}
			alert(out);
			alert(err);
			
		});
		
		$('#btnCopyFileModifyTimeToExifTime').click(function(){
			
		});
	}
};
	
stepManager.add(readGPSLogStep);
